package kr.co.fashionmai.dao;

import java.util.HashMap;
import java.util.List;

import kr.co.fashionmai.vo.FabricHistory;
import kr.co.fashionmai.vo.FabricMain;
import kr.co.fashionmai.vo.FabricSub;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class FabricDao extends SqlMapClientDaoSupport
{
	public List<FabricMain> main(FabricMain fabric)
	{
		return getSqlMapClientTemplate().queryForList("fabric.main", fabric);
	}
	
	public int getTotalCount(FabricMain fabric)
	{
		return (Integer) getSqlMapClientTemplate().queryForObject("fabric.totalCount", fabric);
	}
	
	public void insert(FabricMain fabricMain)
	{
		getSqlMapClientTemplate().insert("fabric.mainInsert", fabricMain);
	}
	
	public void insert(List<FabricSub> fabricSubList)
	{
		for(FabricSub sub : fabricSubList)
		getSqlMapClientTemplate().insert("fabric.subInsert", sub);
	}
	
	public void insert(FabricHistory history)
	{
		getSqlMapClientTemplate().insert("fabric.history", history);
	}
	
	public void delete(String fabric)
	{
		getSqlMapClientTemplate().delete("fabric.mainDelete", fabric);
		getSqlMapClientTemplate().delete("fabric.subDelete", fabric);
		getSqlMapClientTemplate().delete("fabric.historyDelete", fabric);
	}
	
	public void delete(String fabric, String update)
	{
		getSqlMapClientTemplate().delete("fabric.mainDelete", fabric);
		getSqlMapClientTemplate().delete("fabric.subDelete", fabric);
	}
	
	public HashMap select(String fabric)
	{
		HashMap map = new HashMap();
		
		FabricMain fabricMain =  (FabricMain) getSqlMapClientTemplate().queryForObject("fabric.select-fabricMain", fabric);
		List<FabricSub> subList = getSqlMapClientTemplate().queryForList("fabric.select-fabricSubList", fabric);
		List<FabricHistory> historyList = getSqlMapClientTemplate().queryForList("fabric.select-fabricHistoryList", fabric);
		
		map.put("etc", fabricMain.getEtc());
		map.put("fabric", fabricMain.getFabric());
		map.put("stockCount",fabricMain.getStockCount());
		map.put("customer",fabricMain.getCustomer());
		map.put("orderDate",fabricMain.getOrderDate());
		map.put("location",fabricMain.getLocation());
		map.put("subList", subList);
		map.put("historyList", historyList);
	
		return map;
	}
	
	public void update(String fabric)
	{
		getSqlMapClientTemplate().update("fabric.mainUpdate", fabric);
	}
}







